package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.data.DataResult;
import com.dongdongshop.data.ResponseStausEnum;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.service.SellerService;
import com.dongdongshop.util.ShiroUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * @Description
 * @ClassName SellerController
 * @Author RC
 * @date 2020.12.12 16:22
 */
@Controller
@RequestMapping("seller")
public class SellerController {
    @Reference(timeout = 100000,check = false)
    private SellerService sellerService;
    private static final Logger logger = LoggerFactory.getLogger(SellerController.class);

    @RequestMapping("saveSeller")
    @ResponseBody
        public DataResult saveSeller(TbSeller tbSeller){
        //保存  数据有空值 数据库保存异常 ,业务方面导致的没有添加成功 falise
        //可以使用map
        try{
            logger.info("进入增加品牌方法");
            //先随机生成一个加密用的盐
            String salt = ShiroUtils.generateSalt(6);//随机生成一个我么指定长度的字符串
            tbSeller.setSalt(ShiroUtils.generateSalt(6));
            tbSeller.setPassword(ShiroUtils.encryptPassword("MD5",tbSeller.getPassword(),tbSeller.getSalt(), 3));
            tbSeller.setCreateTime(new Date());
            sellerService.saveSeller(tbSeller);
            return DataResult.response(ResponseStausEnum.SUSSCESS);

        } catch (Exception e) {
            logger.info("增加失败", e);
            return DataResult.response(ResponseStausEnum.INTERNAL_SERVER_ERROR);

        }
    }

}

